//
//  MySelfViewController.m
//  Wechat
//
//  Created by FONERY on 2019/9/9.
//  Copyright © 2019 Zhangfan. All rights reserved.
//

#import "MySelfViewController.h"
#import "SettingsViewController.h"
#import "MyInfoViewController.h"
#import "MySelfTableViewCell.h"
#import "ProfileTableViewCell.h"
#import "MySelfModel.h"

@interface MySelfViewController () <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *mySelfArr;
@end

@implementation MySelfViewController

- (NSArray *)mySelfArr {
    if (!_mySelfArr) {
        MySelfModel *scan = [[MySelfModel alloc] init];
        scan.title = @"扫一扫";
        scan.image = @"Card_AddIcon";
        
        MySelfModel *settings = [[MySelfModel alloc] init];
        settings.title = @"设置";
        settings.image = @"tabbar_discover";
        
        MySelfModel *feedback = [[MySelfModel alloc] init];
        feedback.title = @"意见反馈";
        feedback.image = @"tabbar_mainframe";
        
        _mySelfArr = @[[[MySelfModel alloc] init], scan, settings, feedback];
    }
    return _mySelfArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"我";
    self.tableView.tableFooterView = [[UIView alloc] init];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.mySelfArr count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return [ProfileTableViewCell cellWithTableView:tableView];
    }
    
    MySelfTableViewCell *cell = [MySelfTableViewCell cellWithTableView:tableView];
    cell.mySelfModel = self.mySelfArr[indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        return [ProfileTableViewCell cellHeight];
    }
    
    return [MySelfTableViewCell cellHeight];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    MySelfModel *model = self.mySelfArr[indexPath.row];
    if ([model.title isEqualToString:@"扫一扫"]) {
        
    } else if ([model.title isEqualToString:@"设置"]) {
        SettingsViewController *settingsVc = [[SettingsViewController alloc] init];
        [self.navigationController pushViewController:settingsVc animated:YES];
    } else if ([model.title isEqualToString:@"意见反馈"]) {
        
    } else {
        MyInfoViewController *myInfoVc = [[MyInfoViewController alloc] init];
        [self.navigationController pushViewController:myInfoVc animated:YES];
    }
}

@end
